package cn.lingyangwl.agile.system.manager;

import cn.lingyangwl.agile.system.constants.CacheCons;
import cn.lingyangwl.agile.system.mapper.SysSceneMapper;
import cn.lingyangwl.agile.system.model.entity.SysMenuScene;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author shenguangyang
 */
@Slf4j
@Component
public class SysMenuSceneManager extends ServiceImpl<SysSceneMapper, SysMenuScene>
        implements IService<SysMenuScene> {

    @Cacheable(value = CacheCons.MENU_SCENE, key = "#code", unless = "#result == null")
    public SysMenuScene getSceneByCode(String code) {
        SysMenuScene scene = this.getOne(SysMenuScene.lqw().eq(SysMenuScene::getCode, code));
        if (Objects.isNull(scene)) {
            throw new BizException("场景 {} 不存在", code);
        }
        return scene;
    }

    @CacheEvict(value = CacheCons.MENU_SCENE, key = "#code")
    public void cleanCacheByCode(String code) {

    }
}
